package com.longjianghuasheng.logistics.business.mine.fragment

import android.os.Bundle
import androidx.lifecycle.viewModelScope
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.base.BaseTitleFragment
import com.longjianghuasheng.logistics.databinding.FragmentSystemSettingsBinding
import com.longjianghuasheng.logistics.eventViewModel
import com.longjianghuasheng.logistics.ext.hintDialog
import com.longjianghuasheng.logistics.util.CacheUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.hgj.jetpackmvvm.ext.nav

class SystemSettingsFragment :
    BaseTitleFragment<BaseMultiStateViewModel, FragmentSystemSettingsBinding>() {

    override fun layoutId(): Int = R.layout.fragment_system_settings

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        initTitleBar("系统设置")
        mDatabind.run {


            stvModifyPhoneNumber.setOnClickListener {
                navigate(R.id.modifyPhoneNumberFragment)
            }

            stvChangePassword.setOnClickListener {
                navigate(R.id.changePasswordFragment)
            }

            stvLoginOut.setOnClickListener {

                hintDialog("确定退出登录？", {

                    CacheUtil.isLogin = false
                    CacheUtil.token = ""
                    CacheUtil.isDriver = false

                    eventViewModel.loginEvent.value = 0

                    mViewModel.viewModelScope.launch {
                        delay(300)
                        nav().popBackStack(R.id.main2Fragment, false)
                    }
                })
            }

        }
    }

    override fun createObserver() {
        super.createObserver()
    }

    override fun initData() {
        super.initData()
    }

    override fun lazyLoadData() {
        super.lazyLoadData()
    }
}